package com.lagou.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lagou.dao.MenuMapper;
import com.lagou.domain.Menu;
import com.lagou.domain.MenuVO;
import com.lagou.domain.PromotionAd;
import com.lagou.domain.PromotionAdVO;
import com.lagou.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuMapper menuMapper;

    /*查詢所有父子菜单信息*/
    @Override
    public List<Menu> findSubMenuListByPid(Integer pid) {
        List<Menu> subMenuListByPid = menuMapper.findSubMenuListByPid(pid);
        return subMenuListByPid;
    }


    /*查询菜单信息*/
//    @Override
//    public List<Menu> findAllMenu() {
//        List<Menu> list = menuMapper.findAllMenu();
//        return list;
//    }

    /*查询菜单信息分页*/
    @Override
    public PageInfo<Menu> findAllMenu(MenuVO menuVO){
        PageHelper.startPage(menuVO.getCurrentPage(),menuVO.getPageSize());
        List<Menu> allMenu = menuMapper.findAllMenu();
        PageInfo<Menu> menuPageInfo = new PageInfo<>(allMenu);
        return menuPageInfo;
    }


    public Menu findMenuById(Integer id) {
        return menuMapper.findMenuById(id);
    }

    /*添加菜单*/
    @Override
    public void saveMenu(Menu menu) {
        Date date =new Date();
        menu.setCreatedTime(date);
        menu.setUpdatedTime(date);
        menu.setCreatedBy("system");
        menu.setUpdatedBy("system");
        menuMapper.saveMenu(menu);

    }

    /*修改菜单*/
    public void updateMenu(Menu menu) {
        Date date =new Date();
        menu.setUpdatedTime(date);
        menu.setUpdatedBy("system");
        menuMapper.updateMenu(menu);
    }
}
